package jvm;

import java.io.IOException;
import java.io.InputStream;

public class TwoParentTest extends ClassLoader{

    @Override
    protected Class<?> findClass(String name) throws ClassNotFoundException {
        int indexOf = name.lastIndexOf(".")+1;
        String substring = name.substring(indexOf)+".class";
        System.out.println(substring);
        InputStream resourceAsStream =getClass().getResourceAsStream(substring);
        if(resourceAsStream==null){
            throw new ClassNotFoundException("不存在类");
        }
        byte[] bytes=null;
        try {
            bytes = new byte[resourceAsStream.available()];
            resourceAsStream.read(bytes);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return   defineClass(name,bytes,0, bytes.length);
    }
}
